package TeamView;

import TeamService.NameListService;
import TeamService.TeamService;
import Teamdomain.Employee;
import Teamdomain.Programmer;

/**
 * @program: Demo2
 * @description:
 * @author: Yan Guang
 * @create: 2020-04-23 16:03
 */
public class TeamView {
    NameListService nameListService = new NameListService();
    TeamService teamService = new TeamService();

    public void enterMainMenu() {
        boolean isflage = true;
        System.out.println("请输入1-5的数字");
        char key = TSUtility.readMenuSelection();
        while (isflage) {
            listAllEmployees();
            switch (key) {
                case '1':
                    getTeam();
                    break;
                case '2':
                    addMember();
                    break;
                case '3':
                    deleteMember();
                    break;
                case '4':
                    System.out.println("确认是否退出Y/N");
                    char isexit=TSUtility.readConfirmSelection();
                    if (isexit=='Y'){
                        isflage=false;
                    }else {
                        return;
                    }
            }
        }
    }

    private void listAllEmployees() {
        Programmer[] team = teamService.getTeam();
        for (int i = 0; i < team.length; i++) {
            System.out.println(team[i].toString());
        }
    }

    private void getTeam() {
        Programmer[] team=teamService.getTeam();
        for (int i = 0; i < team.length; i++) {
            System.out.println(team[i].toString());
        }
    }

    private void addMember() {
        int id=TSUtility.readInt();
//        try {
//            Employee employee=nameListService.getEmployee(id);
//            teamService.addMember(employee);
//        } catch (TeamException e) {
//            System.out.println("有问题");
//        }
    }

    private void deleteMember() {
        int id=TSUtility.readInt();
        Programmer[] TEAM=teamService.getTeam();
        for (int i = 0; i < TEAM.length; i++) {
            if (TEAM[i].getId()==id){
//                try {
//                    teamService.removeMember(id);
//                } catch (TeamException e) {
//                    System.out.println("有问题");
//                }
            }
        }
    }

    public static void main(String[] args) {
        TeamView teamView = new TeamView();
        teamView.enterMainMenu();
    }
}
